package com.ellricky.baselib.ui.order

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.andr.common.ui.fragment.BaseFragment
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.ResUtil
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.R
import kotlinx.android.synthetic.main.base_fragment_class_consume_record.*
import kotlinx.android.synthetic.main.base_fragment_class_consume_record.tv_title
import java.util.*

class ClassConsumeRecordFragment : BaseFragment<Void, BasePresenter<Void>>() {

    companion object {
        fun newInstance(bundle: Bundle?): ClassConsumeRecordFragment {
            val fragment = ClassConsumeRecordFragment()
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun getContentLayout(): Int {
        return R.layout.base_fragment_class_consume_record
    }

    override fun initUIView(view: View?) {

        tv_title.text = "课消记录"
        ib_back.setOnClickListener {
            activity?.finish()
        }

        val memberId = arguments?.getString(BaseConstant.KEY_ID, "") ?: ""

        val frgList = ArrayList<Fragment>()
        val first =
            ClassConsumeRecordChildFragment.newInstance(BaseConstant.COURSE_TYPE_BASIC, memberId)
        frgList.add(first)
        frgList.add(
            ClassConsumeRecordChildFragment.newInstance(
                BaseConstant.COURSE_TYPE_SPECIAL,
                memberId
            )
        )
        frgList.add(
            ClassConsumeRecordChildFragment.newInstance(
                BaseConstant.COURSE_TYPE_ART,
                memberId
            )
        )
        frgList.add(
            ClassConsumeRecordChildFragment.newInstance(
                BaseConstant.COURSE_TYPE_GIVE,
                memberId
            )
        )

        first.setOnTitleChangeListener(object : ClassConsumeRecordChildFragment.OnConsumeListener {
            override fun onTitleChange(basicNum: Int, specialNum: Int, artNum: Int, giveNum: Int) {
                tabLayout.getTabAt(0)?.text = "美学基础课（$basicNum）"
                tabLayout.getTabAt(1)?.text = "艺术创造（$specialNum）"
                tabLayout.getTabAt(2)?.text = "艺术史（$artNum）"
                tabLayout.getTabAt(3)?.text = "赠课（$giveNum）"

            }
        })
        val tList = listOf(*ResUtil.getStrArr(context, R.array.base_course))
        tabLayout.setUp(childFragmentManager, frgList, tList, vp)
    }
}